using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using DataAccessLayer;

using NUnit.Framework;

namespace Entities
{
    [TestFixture]
    public class ReviewFixture : ConnectionFixture
    {
        private static readonly int rating = 33;
        private static readonly string content = "Test Content";

        private ReviewGateway gateway;
        private RecordingDataSet recordingDataSet;

        private long insertedId;

        [SetUp]
        public void SetUp()
        {
            gateway = new ReviewGateway(Connection);
            recordingDataSet = new RecordingDataSet();
            insertedId = gateway.Insert(rating, content, recordingDataSet);
        }

        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedId, recordingDataSet);
        }

        [Test]
        public void Retrieve()
        {
            RecordingDataSet.ReviewRow row = gateway.FindById(insertedId, new RecordingDataSet());
            Assert.AreEqual(insertedId, row.id);
            Assert.AreEqual(rating, row.rating);
            Assert.AreEqual(content, row.review);
        }

        [Test]
        public void Delete()
        {
            RecordingDataSet emptyDataSet = new RecordingDataSet();
            long deletedId = gateway.Insert(55, "Delete Review", emptyDataSet);

            gateway.Delete(deletedId, emptyDataSet);
            Assert.IsNull(gateway.FindById(deletedId, emptyDataSet));
        }

        [Test]
        public void UpdateReviewField()
        {
            string modifiedReview = "Modified Review";
            RecordingDataSet.ReviewRow row = gateway.FindById(insertedId, recordingDataSet);
            row.review = modifiedReview;
            gateway.Update(recordingDataSet);

            RecordingDataSet updatedReview = new RecordingDataSet();
            Assert.AreEqual(modifiedReview, gateway.FindById(insertedId, updatedReview).review);
        }

        [Test]
        public void UpdateRatingField()
        {
            int modifiedRating = 777;
            RecordingDataSet.ReviewRow row = gateway.FindById(insertedId, recordingDataSet);
            row.rating = modifiedRating;
            gateway.Update(recordingDataSet);

            RecordingDataSet updatedReview = new RecordingDataSet();
            Assert.AreEqual(modifiedRating, gateway.FindById(insertedId, updatedReview).rating);
        }

    }
}
